package com.example.xianglilai_end.Service;

import com.example.xianglilai_end.Bean.*;
import com.example.xianglilai_end.Mapper.BatteriesMapper;
import com.example.xianglilai_end.Mapper.StationsMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class StationsService {
    @Autowired
    private final StationsMapper stationsMapper;
    public StationsService(StationsMapper stationsMapper) {
        this.stationsMapper = stationsMapper;
    }
    /* 获取换电站的信息 */
    public List<Cgstation> getCgstationInfo(){
        List<Cgstation> cgstations = stationsMapper.getCgstationInfo();
        return cgstations;
    }
    /* 获取售后站点service的信息 */
    public List<ServiceStation> getServiceInfo(){
        List<ServiceStation> services = stationsMapper.getServiceInfo();
        return services;
    }

    /* 获取换电数据 */
    public List<ChangeData> getChangeData(){
        List<ChangeData> change_data_list = new ArrayList<>();

        List<ChangeLog> changeLogs = stationsMapper.getChangeLog();
        List<Cgstation> cgstations = stationsMapper.getCgstationInfo();
        for (Cgstation cg : cgstations){
            int service_num = 0;
            System.out.println(cg.getId());
            ChangeData changeData = new ChangeData();
            for (ChangeLog log: changeLogs){
                if (cg.getCode().equals(log.getCg_code())){
                    service_num += 1;
                }
            }
            changeData.setCity(cg.getCity());
            changeData.setCg_code(cg.getCode());
            changeData.setService_num(service_num);
            changeData.setChange_num(0);
            change_data_list.add(changeData);
        }

        return change_data_list;
    }

    public int getUserNum(){
        int num = 0;
        List<User> list = stationsMapper.getUserNum();
        for(int i = 0;i<list.size();i++){
            num++;
        }
        return num;
    }
}
